#include "D:\Project_Dien_Tu\Pic\Cua\main.h"
#include "D:\Project_Dien_Tu\Pic\Cua\lcd_lib_4bit.c"
#byte PortA = 0x05
#byte PortB=0x06
#byte PortC=0x07
#byte PortD=0x08
#bit conguoi = PortB.7
#bit meptrong = PortB.6
#bit mepngoai = PortB.5

int16 sn;
void main()
{
    set_tris_b ( 0xe1 ) ;
    PortB=0xff;
    set_tris_a(0x00);
    set_tris_c(0x00);    
    LCD_init();
    Printf(LCD_putchar,"MO CUA TU DONG  ");
    LCD_putcmd(0xC0);
    Printf(LCD_putchar,"So nguoi: 0");
    enable_interrupts ( GLOBAL ) ;
    enable_interrupts ( INT_RB ) ;
    enable_interrupts (INT_EXT_L2H);
    sn=0;  
    PortC = 0x00;
    PortA = 0xff;
    PortB=0xff;
    while(TRUE)
    {
      PortC=~PortC;
      delay_ms(100);
    }
}

#INT_RB
void ngatRB()
{
   if(conguoi==1)
   {
    OUTPUT_HIGH(PIN_A0);
    OUTPUT_LOW(PIN_A1);
   }
   else
   {
       OUTPUT_HIGH(PIN_A1);
       OUTPUT_LOW(PIN_A0);
   }
   if((conguoi==1&&mepngoai==0)||(conguoi==0&&meptrong==0))
   {
      OUTPUT_HIGH(PIN_A0);
      OUTPUT_HIGH(PIN_A1);
   }
   
}
#INT_EXT
void demnguoi()
{
   sn++;
   LCD_putcmd(0xC0);    
   Printf(LCD_putchar,"So nguoi: \%ld   ",sn);
}

